package com.cqs.learning.classload;

import sun.misc.Launcher;

import java.io.StringReader;

/**
 * -verbose:class
 * <p>
 * 1. 打印被加载的类
 * 2. T[]新建会加载类T,但是不一定会初始化类T
 * 3.
 *
 * @author
 */
public class Singleton {
    private Singleton() {
    }

    private static class LazyHolder {
        static final Singleton INSTANCE = new Singleton();

        static {
            System.out.println("LazyHolder.");
        }

        public static void main(String[] args) {
            System.out.println((char) 46);
            System.out.println("java.lang.InternalError".lastIndexOf(46));
        }
    }

    public static Object getInstance(boolean flag) {
        if (flag) return new LazyHolder[2];
        return LazyHolder.INSTANCE;
    }

    public static void main(String[] args) throws InterruptedException {
        getInstance(true);
        for (int i = 0; i < 10; i++) {
            class MyClassLoader extends ClassLoader {
                @Override
                public Class<?> loadClass(String name) throws ClassNotFoundException {
                    return super.loadClass(name);
                }
            }
        }
        System.out.println("----------------------------------------------");
        Thread.currentThread().join();
    }
}